package com.example.hotelapp.Adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.hotelapp.Base.BaseRvAdapter;
import com.example.hotelapp.Base.BaseRvViewHolder;
import com.example.hotelapp.Bean.RoomDetailBean;
import com.example.hotelapp.R;
import com.example.hotelapp.Utils.AppNetConfig;
import com.shehuan.niv.NiceImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.example.hotelapp.Utils.MyCommonUtils.longToDate;

/**
 * 详细列表适配器
 */
public class DetailAdapter extends BaseRvAdapter<RoomDetailBean.DataBean, DetailAdapter.HomeViewHolder> {

    private DetailAdapter.OnItemClickListener itemClickListener;

    public DetailAdapter(Context context, List<RoomDetailBean.DataBean> datas) {
        super(context, datas);
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void onBindData(HomeViewHolder holder, RoomDetailBean.DataBean dataBean, int position) {
        String chuan = "有窗";
        if (dataBean.getRoomWindow().equals("否")){
            chuan = "无窗";
        }
        holder.type.setText(dataBean.getRoomTypeName());
        holder.youchuan.setText( dataBean.getRoomArea() + "  " + dataBean.getBedname() + "  " + dataBean.getPeopleNumber() + "人入住" + "  " + chuan);
        holder.price.setText("" + dataBean.getRoomPrice());
        Glide.with(context).load(AppNetConfig.HotelImgUrl + dataBean.getRoomPicture()).into(holder.img);
        holder.book.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemClickListener != null){
                    itemClickListener.onItemClick(holder,dataBean.getRoomTypeName(),dataBean.getBedname(),dataBean.getRoomPrice(),dataBean.getId(),position);
                }
            }
        });

    }

    @NonNull
    @Override
    public HomeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_detail, parent, false);
        return new HomeViewHolder(view);
    }

    public static class HomeViewHolder extends BaseRvViewHolder {
        @BindView(R.id.tt)
        NiceImageView img;
        @BindView(R.id.tv_title)
        TextView type;
        @BindView(R.id.tv_shuoming)
        TextView youchuan;
        @BindView(R.id.login)
        Button book;
        @BindView(R.id.tv_price)
        TextView price;

        public HomeViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    //点击事件接口
    public interface OnItemClickListener {
        void onItemClick(RecyclerView.ViewHolder viewHolder, String typename, String bedname,Double price,int id, int position);
    }

    //设置点击事件的方法
    public void setItemClickListener(DetailAdapter.OnItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

}

